﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MoreSetPage : MonoBehaviour
{
    public Button riseBtn;
    public Button appendScore;
    public Button exitRoom;
    public Button closeBtn;

    void Start()
    {
        riseBtn.onClick.RemoveAllListeners();
        riseBtn.onClick.AddListener(RiseBtnClick);
        appendScore.onClick.RemoveAllListeners();
        appendScore.onClick.AddListener(AppendScoreBtnClick);
        exitRoom.onClick.RemoveAllListeners();
        exitRoom.onClick.AddListener(ExitedRoomBtnClick);
        closeBtn.onClick.RemoveAllListeners();
        closeBtn.onClick.AddListener(BgBtnClick);
        InitBtnState();
    }

    public void InitBtnState()
    {
        if (GameRoomModel.GetInstance().RoomState == 0 || GameRoomModel.GetInstance().RoomState == 4 ||GameData.GetInstance().locationIndex==-1)
        {
            exitRoom.GetComponent<Button>().interactable = true;

            if (GameData.GetInstance().locationIndex > -1)
            {
                riseBtn.GetComponent<Button>().interactable = true;
                appendScore.GetComponent<Button>().interactable = true;
            }
            else
            {
                riseBtn.GetComponent<Button>().interactable = false;
                appendScore.GetComponent<Button>().interactable = false;
            }
        }
        else
        {     
            riseBtn.GetComponent<Button>().interactable = false;
            appendScore.GetComponent<Button>().interactable = false;
            exitRoom.GetComponent<Button>().interactable = false;
        }
    }

    private void RiseBtnClick()
    {
        if (GameRoomModel.GetInstance().RoomState == 0 || GameRoomModel.GetInstance().RoomState == 4)
        {
            MessageManager.GetInstance().SendMsg1231(0, int.Parse(GameData.GetInstance().userID));
            BgBtnClick();
        }
        else
        {
            Debug.Log("游戏中不能站起！");
            BgBtnClick();
        }
    }

    private void AppendScoreBtnClick()
    {
        UIManager.ChangeUI(UIManager.PageState.AppendScorePage, obj =>
        {
            obj.GetComponent<AppendScorePage>().InformationSetting();
        });

        BgBtnClick();
    }

    private void ExitedRoomBtnClick()
    {
        MessageManager.GetInstance().SendMsg1229(int.Parse(GameData.GetInstance().userID));
        BgBtnClick();
    }

    private void BgBtnClick()
    {
        gameObject.SetActive(false);
    }
}
